package com.example.wechat.csdnandroid.activity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.viewpager.widget.ViewPager;

import com.example.wechat.csdnandroid.R;
import com.example.wechat.csdnandroid.adapter.ViewPagerFragmentPagerAdapter;
import com.example.wechat.csdnandroid.utils.ToolbarUtils;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

public class ViewPagerActivity extends AppCompatActivity {

    private ViewPager vpAvp;
    private ArrayList<String> listTitle = new ArrayList<>();
    private TabLayout tlAvp;
    private Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_pager);
        initView();
        initData();
    }

    private void initData() {
        ToolbarUtils.setToolbar(R.string.local,toolbar,this);
        listTitle.add("本地影片");
        listTitle.add("本地图片");
        for (int i = 0; i < listTitle.size(); i++) {
            tlAvp.addTab(tlAvp.newTab().setText(listTitle.get(i)));
        }
        ViewPagerFragmentPagerAdapter viewPagerFragmentPagerAdapter = new ViewPagerFragmentPagerAdapter(getSupportFragmentManager(), listTitle);
        vpAvp.setAdapter(viewPagerFragmentPagerAdapter);
        tlAvp.setupWithViewPager(vpAvp);
    }

    private void initView() {
        tlAvp = (TabLayout) findViewById(R.id.tl_avp);
        vpAvp = (ViewPager) findViewById(R.id.vp_avp);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
    }
}
